#include "../../include/myfunc.h"

//日志系统: 将客户端的请求信息、连接时间、操作记录及操作时间写入/var/log/syslog文件中
//第二个参数为sever接收命令的buffer名，如输出结果：2022-05-01 23:44:40 client: cd files/

//日志级别,共0-7八个级别
//LOG_EMERG     0级，系统不可用
//LOG_ALERT     1级，应该立即被解决的问题
//LOG_CRIT      2级，重要错误
//LOG_ERR       3级，正常错误
//LOG_WARNING   4级，警告
//LOG_NOTICE    5级，非错误情况的重要提示
//LOG_INFO      6级，正常信息
//LOG_DEBUG     7级，调试信息

void logsystem(int level, const char *logMessage)
{
    time_t timeInSeconds = time(NULL);
    struct tm *calendarTime = localtime(&timeInSeconds);
    syslog(LOG_INFO,
           "%04d-%02d-%02d %02d:%02d:%02d client: %s",
           calendarTime->tm_year + 1900,
           calendarTime->tm_mon + 1,
           calendarTime->tm_mday,
           calendarTime->tm_hour,
           calendarTime->tm_min,
           calendarTime->tm_sec,
           logMessage);
}